// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
require('../GlobalDefines/GlobalDefines')
cc.Class({
    extends: cc.Component,

    properties: {
        card:{
            default: null,
            type:cc.Prefab
        },
        selfHandCardRoot:{
            default: null,
            type:cc.Node
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        var GameLogic = require('../GameLogic');
        var DBTools = require("../DB/DBTools");

        DBTools.prepareDB('Jsons/cards');
        DBTools.prepareDB('Jsons/npc');
        DBTools.prepareDB('Jsons/attack_skill');

        cc.gamelogic = new GameLogic();
        cc.cardEventCenter = require("../EventCenter");
        cc.userData = require("../Data/UserData");
    },

    onEnable(){
        cc.systemEvent.on(GameEvent_InitPlayer_End, this.onInitPlayerEnd)

        cc.systemEvent.on(GameEvent_DrawCards, this.onDrawCards)
    },

    onDisable(){

    },

    onInitPlayerEnd(data){
        cc.userData.gameInfo = data
    },
    
    onDrawCards(data){
        console.log(data.detail)
    },
    

    start () {
        var GamePlayer = require("../Model/GamePlayer");
        var DBTools = require("../DB/DBTools");
        setTimeout(function(){
            cc.gamelogic.StartGame(DBTools.Debug_CreateGamePlayer(1), DBTools.Debug_CreateGamePlayer(2));
        }, 3000)
    },

    addHandCardToView(gameplayer, cardid){
        if(cc.userData.id == gameplayer.id){
            var instance = cc.instance(card);
            selfHandCardRoot.addChild(instance);
        }
    }
    // update (dt) {},
});
